package org.watchrecords.constants;

import org.apache.commons.lang.ArrayUtils;

public enum Role {
    ADMINISTRATOR("administrator", "Administrator", Permission.values()),
    
    WATCHMAN("watchman", "Watchman", new Permission[] {
            Permission.VIEW_USERS,
            Permission.EDIT_OFFENDER,
            Permission.VIEW_CELL_LOG,
            Permission.VIEW_STATISTICS,
            Permission.EDIT_INCIDENT,
    }),
    
    COURT("court", "Court Member", new Permission[] {
            Permission.VIEW_USERS,
            Permission.VIEW_CELL_LOG,
            Permission.VIEW_STATISTICS,
    }),
    ;
    
    private String id;
    private String name;
    private Permission[] permissions;
    
    private Role(String id, String name, Permission[] permissions) {
        this.id = id;
        this.name = name;
        this.permissions = permissions;
    }
    
    public String getId() {
        return id;
    }
    
    public String toString() {
        return name;
    }
    
    public Permission[] getPermissions() {
        return permissions;
    }
    
    public boolean haveAnyPermission(Permission... permissions) {
        for (Permission permission: permissions) {
            if (ArrayUtils.contains(this.permissions, permission)) {
                return true;
            }
        }
        
        return false;
    }
}
